package com.ruoyi.deeplearn.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.deeplearn.domain.DeepModule;
import com.ruoyi.deeplearn.service.IDeepModuleService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 模块Controller
 *
 * @author 任伟伟
 * @date 2022-12-10
 */
@RestController
@RequestMapping("/deeplearn/module")
public class DeepModuleController extends BaseController
{
    @Autowired
    private IDeepModuleService deepModuleService;

    /**
     * 查询模块列表
     */
//    @PreAuthorize("@ss.hasPermi('deeplearn:module:list')")
    @GetMapping("/list")
    public TableDataInfo list(DeepModule deepModule)
    {
        startPage();
        List<DeepModule> list = deepModuleService.selectDeepModuleList(deepModule);
        return getDataTable(list);
    }

//    @PreAuthorize("@ss.hasPermi('deeplearn:module:list')")
    @GetMapping("/list/all")
    public AjaxResult listAll(DeepModule deepModule)
    {
        List<DeepModule> list = deepModuleService.selectDeepModuleList(deepModule);
        return success(list);
    }

    /**
     * 导出模块列表
     */
//    @PreAuthorize("@ss.hasPermi('deeplearn:module:export')")
    @Log(title = "模块", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DeepModule deepModule)
    {
        List<DeepModule> list = deepModuleService.selectDeepModuleList(deepModule);
        ExcelUtil<DeepModule> util = new ExcelUtil<DeepModule>(DeepModule.class);
        util.exportExcel(response, list, "模块数据");
    }

    /**
     * 获取模块详细信息
     */
//    @PreAuthorize("@ss.hasPermi('deeplearn:module:query')")
    @GetMapping(value = "/{moduleId}")
    public AjaxResult getInfo(@PathVariable("moduleId") Long moduleId)
    {
        return success(deepModuleService.selectDeepModuleByModuleId(moduleId));
    }

    /**
     * 新增模块
     */
//    @PreAuthorize("@ss.hasPermi('deeplearn:module:add')")
    @Log(title = "模块", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DeepModule deepModule)
    {
        return toAjax(deepModuleService.insertDeepModule(deepModule));
    }

    /**
     * 修改模块
     */
//    @PreAuthorize("@ss.hasPermi('deeplearn:module:edit')")
    @Log(title = "模块", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DeepModule deepModule)
    {
        return toAjax(deepModuleService.updateDeepModule(deepModule));
    }

    /**
     * 删除模块
     */
//    @PreAuthorize("@ss.hasPermi('deeplearn:module:remove')")
    @Log(title = "模块", businessType = BusinessType.DELETE)
	@DeleteMapping("/{moduleIds}")
    public AjaxResult remove(@PathVariable Long[] moduleIds)
    {
        return toAjax(deepModuleService.deleteDeepModuleByModuleIds(moduleIds));
    }
}
